﻿using Backend.Data.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Backend.Data.Mappings
{
    public class CityMap : EntityTypeConfiguration<City>
    {
        public CityMap()
        {
            //table
            ToTable("Citys");

            //pk
            HasKey(t => t.Id);

            //property
            Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(t => t.Name)
                .IsRequired();

            //relationship
            HasRequired(t => t.State)
                .WithMany(c => c.Citys)
                .HasForeignKey(t => t.StateId)
                .WillCascadeOnDelete(false);

        }
    }
}
